using Windows.UI.Xaml;
using GalaSoft.MvvmLight.Ioc;
using GalaSoft.MvvmLight.Messaging;
using Microsoft.Practices.ServiceLocation;

namespace BuddyTracker.ViewModel
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// </summary>
    public class ViewModelLocator
    {
        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            SimpleIoc.Default.Register<MainViewModel>(); //Inversion of Control
        }

        /// <summary>
        /// My Main ViewModel linked to both pages.
        /// </summary>
        public MainViewModel Main
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MainViewModel>();
            }
        }
        
        /// <summary>
        /// Cleans up all the ViewModels.
        /// </summary>
        public static void Cleanup()
        {
            var viewModelLocator = (ViewModelLocator) Application.Current.Resources["Locator"];
            viewModelLocator.Main.Cleanup();

            Messenger.Reset();
        }
    }
}